package com.yanqu.road.server.cmd.cross3;

import com.yanqu.road.logic.xlogic.server.XServerNameMap;
import com.yanqu.road.pb.cross3.server.CrossChannelServerProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.manger.cross3.GameXServerNameMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameProtocol;
import io.netty.channel.ChannelHandlerContext;

@Cmd(code = GameProtocol.S_SYNC_SERVER_NAME_FROM_CROSS3, desc = "跨地区同步区服名称")
public class SyncServerNameFromCross3Cmd implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        XServerNameMap serverNameMap = GameXServerNameMgr.getServerNameMap();
        CrossChannelServerProto.ServerNameListMsg reqMsg = CrossChannelServerProto.ServerNameListMsg.parseFrom(packet.getBytes());
        for (CrossChannelServerProto.ServerNameMsg msg : reqMsg.getNameListList()) {
            serverNameMap.addServerName(msg.getChannelId(), msg.getServerId(), msg.getServerName());
        }
    }
}
